﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using spring.salesman.data;
using Newtonsoft.Json;

namespace spring.salesman.Wcf
{
    [ServiceContract(Namespace = "spring.wcf")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class DataService
    {
        // 要使用 HTTP GET，请添加 [WebGet] 特性。(默认 ResponseFormat 为 WebMessageFormat.Json)
        // 要创建返回 XML 的操作，
        //     请添加 [WebGet(ResponseFormat=WebMessageFormat.Xml)]，
        //     并在操作正文中包括以下行:
        //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        [OperationContract]
        public void DoWork()
        {
            // 在此处添加操作实现
            return;
        }

        // 在此处添加更多操作并使用 [OperationContract] 标记它们

        [OperationContract]
        public string UserCard() {

            List<d_UserCard> list = null;
            using (SalemanDBEntities entites = new SalemanDBEntities())
            {
                list = entites.d_UserCard.ToList<d_UserCard>();

            }
            string output = "{\"totalCount\":\"" + list.Count + "\",\"rows\":" + JsonConvert.SerializeObject(list) + "}";
            return output;
        }

    }
}
